package com.example.notification;


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.widget.TextView;

public class ExemploCriaNotificacao extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String extra = "" + (SystemClock.uptimeMillis() / 1000);
        
        TextView text = new TextView(this);
        text.setText("Uma notificacao foi disparada com extra = '" + extra + "'.");

        setContentView(text);

        String tickerText = "Voce recebeu um mensagem";
        CharSequence titulo = "Maria";
        CharSequence mensagem = "Exemplo de notificacao";

        criarNotificacao(this, tickerText, titulo, mensagem,
        		ExemploExecutaNotificacao.class, extra);
    }

	private void criarNotificacao(
			Context context, CharSequence mensagemBarraStatus,
			CharSequence titulo, CharSequence mensagem,
			Class<?> activity, String extra) {

		Intent i = new Intent(this, activity);
		i.putExtra("extraString", extra);
		PendingIntent p = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

		Notification n = new Notification(R.drawable.icon, mensagemBarraStatus, System.currentTimeMillis());
		n.setLatestEventInfo(context, titulo, mensagem, p);

		//n.vibrate = new long[] { 100, 250, 100, 500 };

		n.flags = Notification.FLAG_INSISTENT
				| Notification.FLAG_AUTO_CANCEL;

		n.defaults = Notification.DEFAULT_SOUND
				   | Notification.DEFAULT_LIGHTS
				   | Notification.DEFAULT_VIBRATE;
		
		NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		nm.notify(R.string.app_name, n);
	}
}